class GitDataReferences
  attr_accessor :github

  def initialize(github)
    @github = github
  end

  def getReference(repo, ref, user=nil)
    username = user == nil ? @github.username : user
    @github.get(
        'repos/%s/%s/git/refs/%s' % [username, repo, ref])

    def getReferences(repo, subnamespace=nil, user=nil)
      username = user == nil ? @github.username : user
      url = 'repos/%s/%s/git/refs' % [repo, username]
      if subnamespace
        url = subnamespace[0] == '/' ? '%s/%s' % [url, subnamespace]
        : '%s/%s/' % [url, subnamespace]
      end
      @github.get(url)
    end

    def createReference(repo, ref, sha, user=nil)
      username = user == nil ? @github.username : user
      params = {
          :ref => ref,
          :sha => sha
      }
      data = params.to_json
      @github.post('repos/%s/%s/git/refs' % [username, repo], data)
    end

    def editReference(repo, sha, force=FALSE, user=nil)
      username = user == nil ? @github.username : user
      params = {
          :sha => sha,
          :force => force
      }
      data = params.to_json
      @github.patch('repos/%s/%s/git/refs' % [username, repo], data)
    end
  end
end

